package com.djc8.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.djc8.model.Model;

/**
 * Servlet implementation class BookServlet
 */
public class BookServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BookServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String bookID=request.getParameter("bookID");
		try
		{
			if(bookID!=null && !bookID.equals(""))
			{
				Model m=new Model();
				request.getSession().setAttribute("bookTemp", m.getBook(bookID));
				List list=m.getBookReviewsByBookID(Integer.parseInt(bookID));
				request.getSession().setAttribute("bookRevewByBookID", list);
				System.out.println(list.size());
				request.getRequestDispatcher("/WEB-INF/jsp/BookJSP.jsp").forward(request, response);
			}

		}
		catch(Exception ex)
		{
			
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
